package com.ruoyi.system.service.impl;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.*;
import com.ruoyi.common.core.domain.entity.*;
import com.ruoyi.common.core.domain.vo.*;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.IRaBaseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @DATE : 2024/05/22 13:21
 */
@Service
public class RaBaseServiceImpl implements IRaBaseService {

    @Resource
    private RaBaseMapper mapper;

    @Resource
    private FrontTermMapper frontTermMapper;

    @Resource
    private ArmFrontTermMapper armFrontTermMapper;

    @Resource
    private RaBaseRealMapper raBaseRealMapper;

    @Resource
    AiConfigMapper aiConfigMapper;

    @Resource
    private TjlResultMapper tjlResultMapper;

    @Resource
    private MhOrangeMapper mhOrangeMapper;


    // 正式环境
    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public RaBase selectRaBaseByOne() {
        // 本地测试环境
        // return mapper.selectRaBaseByOne();
        // 正式环境
        return this.raBaseReal();
    }

    @Override
    public AjaxResult selectRead() {
        // 本地环境
        // RaBase raBase = mapper.selectRaBaseByOne();
        // 正式环境
        RaBase raBase = this.raBaseReal();
        return AjaxResult.success(raBase);
    }

    @Override
    public AjaxResult listChange(ChangeDto changeDto) {
        List<String> sqlStr = new ArrayList<>();
        String startTime;
        String endTime = "";
        Map<String, Object> queryMap = new HashMap<>();
        // 一期
        List<String> fieldFormYq = changeDto.getFieldFormYq();
        // 一期进水流量
        if (fieldFormYq.contains("1")) {
            sqlStr.add("Convert(decimal(18,2),[YQ_JSLL]) as YQ_JSLL");
        }
        // 一期石灰投加量
        if (fieldFormYq.contains("2")) {
            sqlStr.add("Convert(decimal(18,2),[shsjtjll4]) as shsjtjll4");
        }
        // 一期加药流量
        if (fieldFormYq.contains("3")) {
            sqlStr.add("Convert(decimal(18,2),[yq_jy_ssll]) as yq_jy_ssll");
        }
        // 一期加药投加量
        if (fieldFormYq.contains("4")) {
            sqlStr.add("Convert(decimal(18,2),[yq_tjl_show]) as yq_tjl_show");
        }
        // 一期沉淀后浊度
        if (fieldFormYq.contains("5")) {
            sqlStr.add("Convert(decimal(18,2),[DITT11]) as DITT11");
        }

        // 二期
        List<String> fieldFormEq = changeDto.getFieldFormEq();
        // 二期进水流量
        if (fieldFormEq.contains("6")) {
            sqlStr.add("Convert(decimal(18,2),[FIT102]) as FIT102");
        }
        // 二期石灰投加量
        if (fieldFormEq.contains("7")) {
            sqlStr.add("Convert(decimal(18,2),[shsjtjll2]) as shsjtjll2");
        }
        // 二期加药流量
        if (fieldFormEq.contains("8")) {
            sqlStr.add("Convert(decimal(18,2),[eq_jy_ssll]) as eq_jy_ssll");
        }
        // 二期加药投加量
        if (fieldFormEq.contains("9")) {
            sqlStr.add("Convert(decimal(18,2),[eq_tjl_show]) as eq_tjl_show");
        }
        // 二期1#沉淀后浊度
        if (fieldFormEq.contains("10")) {
            sqlStr.add("Convert(decimal(18,2),[CDC1_ZD_Z]) as CDC1_ZD_Z");
        }
        // 二期2#沉淀后浊度
        if (fieldFormEq.contains("11")) {
            sqlStr.add("Convert(decimal(18,2),[CDC2_ZD_Z]) as CDC2_ZD_Z");
        }

        // 原水
        List<String> fieldFormYs = changeDto.getFieldFormYs();
        // 盖竹原水浊度
        if (fieldFormYs.contains("12")) {
            sqlStr.add("Convert(decimal(18,2),[MIT101_T]) as MIT101_T");
        }
        // 盖竹原水PH
        if (fieldFormYs.contains("13")) {
            sqlStr.add("Convert(decimal(18,2),[AIT101_PH]) as AIT101_PH");
        }
        // 盖竹原水温度
        if (fieldFormYs.contains("14")) {
            sqlStr.add("Convert(decimal(18,2),[AIT101_T]) as AIT101_T");
        }
        // 高楼原水PH
        if (fieldFormYs.contains("15")) {
            sqlStr.add("Convert(decimal(18,2),[jnysph]) as jnysph");
        }
        // 高楼原水浊度
        if (fieldFormYs.contains("16")) {
            sqlStr.add("Convert(decimal(18,2),[jnyszd]) as jnyszd");
        }
        sqlStr.add("date_time");
        // 第一个：查询字段拼接
        String selectSql = StringUtils.join(sqlStr, ",");

        // 第二个：起始时间
        if (!changeDto.getStartDate().isEmpty()) {
            startTime = changeDto.getStartDate();
            endTime = changeDto.getEndDate();
        } else {
            startTime = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", DateUtils.addHours(new Date(), -changeDto.getSetTime().get(0)));
            endTime = DateUtils.getTime();
        }

        // 第三个：查询间隔 00:05:00 五分钟间隔
        String querySpace = changeDto.getQuerySpace();
        Long querySpaceToLong = DateUtils.StrToNum(querySpace);

        // 组装查询sql条件
        queryMap.put("selectSql", selectSql);
        queryMap.put("startTime", startTime);
        queryMap.put("endTime", endTime);
        queryMap.put("querySpaceToLong", querySpaceToLong);

        // 执行sql
        List<ChangeResultDto> changeResultDtos = mapper.changeList(queryMap);
        List<Date> dateTimes = changeResultDtos.stream().map(ChangeResultDto::getDateTime).collect(Collectors.toList());
        ChangeVo changeVo = new ChangeVo();
        changeVo.setDateTimes(dateTimes);

        // 一期进水流量
        if (fieldFormYq.contains("1")) {
            List<Double> yqJslls = changeResultDtos.stream().map(ChangeResultDto::getYqJsll).collect(Collectors.toList());
            changeVo.setYqJslls(yqJslls);
        }
        // 一期石灰投加量
        if (fieldFormYq.contains("2")) {
            List<Double> shsjtjll4s = changeResultDtos.stream().map(ChangeResultDto::getShsjtjll4).collect(Collectors.toList());
            changeVo.setShsjtjll4s(shsjtjll4s);
        }
        // 一期加药流量
        if (fieldFormYq.contains("3")) {
            List<Double> yqJySslls = changeResultDtos.stream().map(ChangeResultDto::getYqJySsll).collect(Collectors.toList());
            changeVo.setYqJySslls(yqJySslls);
        }
        // 一期加药投加量
        if (fieldFormYq.contains("4")) {
            List<Double> yqTjlShows = changeResultDtos.stream().map(ChangeResultDto::getYqTjlShow).collect(Collectors.toList());
            changeVo.setYqTjlShows(yqTjlShows);
        }
        // 一期沉淀后浊度
        if (fieldFormYq.contains("5")) {
            List<Double> ditt11s = changeResultDtos.stream().map(ChangeResultDto::getDitt11).collect(Collectors.toList());
            changeVo.setDitt11s(ditt11s);
        }
        // 二期进水流量
        if (fieldFormEq.contains("6")) {
            List<Double> fit102s = changeResultDtos.stream().map(ChangeResultDto::getFit102).collect(Collectors.toList());
            changeVo.setFit102s(fit102s);
        }
        // 二期石灰投加量
        if (fieldFormEq.contains("7")) {
            List<Double> shsjtjll2s = changeResultDtos.stream().map(ChangeResultDto::getShsjtjll2).collect(Collectors.toList());
            changeVo.setShsjtjll2s(shsjtjll2s);
        }
        // 二期加药流量
        if (fieldFormEq.contains("8")) {
            List<Double> eqJySslls = changeResultDtos.stream().map(ChangeResultDto::getEqJySsll).collect(Collectors.toList());
            changeVo.setEqJySslls(eqJySslls);
        }
        // 二期加药投加量
        if (fieldFormEq.contains("9")) {
            List<Double> eqTjlShows = changeResultDtos.stream().map(ChangeResultDto::getEqTjlShow).collect(Collectors.toList());
            changeVo.setEqTjlShows(eqTjlShows);
        }
        // 二期1#沉淀后浊度
        if (fieldFormEq.contains("10")) {
            List<Double> cdc1ZdZs = changeResultDtos.stream().map(ChangeResultDto::getCdc1ZdZ).collect(Collectors.toList());
            changeVo.setCdc1ZdZs(cdc1ZdZs);
        }
        // 二期2#沉淀后浊度
        if (fieldFormEq.contains("11")) {
            List<Double> cdc2ZdZs = changeResultDtos.stream().map(ChangeResultDto::getCdc2ZdZ).collect(Collectors.toList());
            changeVo.setCdc2ZdZs(cdc2ZdZs);
        }
        // 盖竹原水浊度
        if (fieldFormYs.contains("12")) {
            List<Double> mit101Ts = changeResultDtos.stream().map(ChangeResultDto::getMit101T).collect(Collectors.toList());
            changeVo.setMit101Ts(mit101Ts);
        }
        // 盖竹原水PH
        if (fieldFormYs.contains("13")) {
            List<Double> ait101Phs = changeResultDtos.stream().map(ChangeResultDto::getAit101Ph).collect(Collectors.toList());
            changeVo.setAit101Phs(ait101Phs);
        }
        // 盖竹原水温度
        if (fieldFormYs.contains("14")) {
            List<Double> ait101Ts = changeResultDtos.stream().map(ChangeResultDto::getAit101T).collect(Collectors.toList());
            changeVo.setAit101Ts(ait101Ts);
        }
        // 高楼原水PH
        if (fieldFormYs.contains("15")) {
            List<Double> jnysphs = changeResultDtos.stream().map(ChangeResultDto::getJnysph).collect(Collectors.toList());
            changeVo.setJnysphs(jnysphs);
        }
        // 高楼原水浊度
        if (fieldFormYs.contains("16")) {
            List<Double> jnyszds = changeResultDtos.stream().map(ChangeResultDto::getJnyszd).collect(Collectors.toList());
            changeVo.setJnyszds(jnyszds);
        }
        return AjaxResult.success(changeVo);
    }

    @Override
    public List<ChangeResultDto> listChangeExport(ChangeDto changeDto) {
        List<String> sqlStr = new ArrayList<>();
        String startTime;
        String endTime = "";
        Map<String, Object> queryMap = new HashMap<>();
        // 一期
        List<String> fieldFormYq = changeDto.getFieldFormYq();
        if (fieldFormYq != null && fieldFormYq.size() > 0) {
            // 一期进水流量
            if (fieldFormYq.contains("1")) {
                sqlStr.add("Convert(decimal(18,2),[YQ_JSLL]) as YQ_JSLL");
            }
            // 一期石灰投加量
            if (fieldFormYq.contains("2")) {
                sqlStr.add("Convert(decimal(18,2),[shsjtjll4]) as shsjtjll4");
            }
            // 一期加药流量
            if (fieldFormYq.contains("3")) {
                sqlStr.add("Convert(decimal(18,2),[yq_jy_ssll]) as yq_jy_ssll");
            }
            // 一期加药投加量
            if (fieldFormYq.contains("4")) {
                sqlStr.add("Convert(decimal(18,2),[yq_tjl_show]) as yq_tjl_show");
            }
            // 一期沉淀后浊度
            if (fieldFormYq.contains("5")) {
                sqlStr.add("Convert(decimal(18,2),[DITT11]) as DITT11");
            }
        }

        // 二期
        List<String> fieldFormEq = changeDto.getFieldFormEq();
        if (fieldFormEq != null && fieldFormEq.size() > 0) {
            // 二期进水流量
            if (fieldFormEq.contains("6")) {
                sqlStr.add("Convert(decimal(18,2),[FIT102]) as FIT102");
            }
            // 二期石灰投加量
            if (fieldFormEq.contains("7")) {
                sqlStr.add("Convert(decimal(18,2),[shsjtjll2]) as shsjtjll2");
            }
            // 二期加药流量
            if (fieldFormEq.contains("8")) {
                sqlStr.add("Convert(decimal(18,2),[eq_jy_ssll]) as eq_jy_ssll");
            }
            // 二期加药投加量
            if (fieldFormEq.contains("9")) {
                sqlStr.add("Convert(decimal(18,2),[eq_tjl_show]) as eq_tjl_show");
            }
            // 二期1#沉淀后浊度
            if (fieldFormEq.contains("10")) {
                sqlStr.add("Convert(decimal(18,2),[CDC1_ZD_Z]) as CDC1_ZD_Z");
            }
            // 二期2#沉淀后浊度
            if (fieldFormEq.contains("11")) {
                sqlStr.add("Convert(decimal(18,2),[CDC2_ZD_Z]) as CDC2_ZD_Z");
            }
        }

        // 原水
        List<String> fieldFormYs = changeDto.getFieldFormYs();
        if (fieldFormYs != null && fieldFormYs.size() > 0) {
            // 盖竹原水浊度
            if (fieldFormYs.contains("12")) {
                sqlStr.add("Convert(decimal(18,2),[MIT101_T]) as MIT101_T");
            }
            // 盖竹原水PH
            if (fieldFormYs.contains("13")) {
                sqlStr.add("Convert(decimal(18,2),[AIT101_PH]) as AIT101_PH");
            }
            // 盖竹原水温度
            if (fieldFormYs.contains("14")) {
                sqlStr.add("Convert(decimal(18,2),[AIT101_T]) as AIT101_T");
            }
            // 高楼原水PH
            if (fieldFormYs.contains("15")) {
                sqlStr.add("Convert(decimal(18,2),[jnysph]) as jnysph");
            }
            // 高楼原水浊度
            if (fieldFormYs.contains("16")) {
                sqlStr.add("Convert(decimal(18,2),[jnyszd]) as jnyszd");
            }
        }
        sqlStr.add("date_time");
        // 第一个：查询字段拼接
        String selectSql = StringUtils.join(sqlStr, ",");

        // 第二个：起始时间
        if (!changeDto.getStartDate().isEmpty()) {
            startTime = changeDto.getStartDate();
            endTime = changeDto.getEndDate();
        } else {
            startTime = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", DateUtils.addHours(new Date(), -changeDto.getSetTime().get(0)));
            endTime = DateUtils.getTime();
        }

        // 第三个：查询间隔 00:05:00 五分钟间隔
        String querySpace = changeDto.getQuerySpace();
        Long querySpaceToLong = DateUtils.StrToNum(querySpace);

        // 组装查询sql条件
        queryMap.put("selectSql", selectSql);
        queryMap.put("startTime", startTime);
        queryMap.put("endTime", endTime);
        queryMap.put("querySpaceToLong", querySpaceToLong);
        // 执行sql
        return mapper.changeList(queryMap);
    }

    @Override
    public YqByEqVo queryModel(QueryDto queryDto) {
        // 获取最新的一条数据
        RaBase raBase = mapper.selectRaBaseByOne();

        // queryDto.setMit101T(raBase.getMit101T());
        // queryDto.setAit101Ph(raBase.getAit101Ph());
        // queryDto.setAit101T(raBase.getAit101T());
        // queryDto.setJnyszd(raBase.getJnyszd());
        // queryDto.setJnysph(raBase.getJnysph());
        // queryDto.setYqJsll(raBase.getYqJsll());
        // queryDto.setFit102(raBase.getFit102());
        // queryDto.setShsjtjll4(raBase.getShsjtjll4());
        // queryDto.setShsjtjll2(raBase.getShsjtjll2());

        return this.queryModelByArt(queryDto, raBase);
    }

    @Override
    public void queryModelAi() {
        // 获取最新的一条数据
        RaBase raBase = mapper.selectRaBaseByOne();
        // 获取自动化配置
        AiConfig aiConfig = aiConfigMapper.selectOne();
        TjlResult tjlResult = new TjlResult();
        QueryDto queryDto = new QueryDto();
        // 盖竹
        queryDto.setMit101T(raBase.getMit101T());
        queryDto.setAit101Ph(raBase.getAit101Ph());
        queryDto.setAit101T(raBase.getAit101T());
        // 高楼
        queryDto.setJnyszd(raBase.getJnyszd());
        queryDto.setJnysph(raBase.getJnysph());
        // 石灰投加量
        queryDto.setShsjtjll4(raBase.getShsjtjll4());
        queryDto.setShsjtjll2(raBase.getShsjtjll2());
        // 水量
        queryDto.setYqJsll(raBase.getYqJsll());
        queryDto.setFit102(raBase.getFit102());
        // 一期参考盖竹/高楼  默认参考盖竹
        if (Boolean.TRUE.equals(aiConfig.getReferenceTypeGz()) && Boolean.FALSE.equals(aiConfig.getReferenceTypeGl())) {
            queryDto.setReferenceType(1);
        } else {
            queryDto.setReferenceType(2);
        }
        // 查询时间间隔 默认3小时
        queryDto.setQuerySpace(aiConfig.getQuerySpace());
        // 查询范围 默认查三年
        List<String> startDateList = new ArrayList<>();
        int startDate = aiConfig.getStartDate();
        int monthSpace = aiConfig.getMonthSpace();
        StringBuilder sqlDateSb = new StringBuilder();
        String year = "";
        // 五年
        if (startDate == 1) {
            year = DateUtils.getYear(-5);
        }
        // 三年
        if (startDate == 2) {
            year = DateUtils.getYear(-3);
        }
        // 两年
        if (startDate == 3) {
            year = DateUtils.getYear(-2);
        }
        // 一年
        if (startDate == 4) {
            year = DateUtils.getYear(-1);
        }
        if (monthSpace == 0) {
            sqlDateSb.append("and (date_time between '");
            sqlDateSb.append(year);
            sqlDateSb.append("' and '");
            sqlDateSb.append(DateUtils.getTime());
            sqlDateSb.append("')");
        } else {
            // 一年
            if (startDate == 4) {
                sqlDateSb.append("and ((date_time between '");
                sqlDateSb.append(DateUtils.getMon(-monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.getTime());
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("'))");
            }
            // 两年
            if (startDate == 3) {
                sqlDateSb.append("and ((date_time between '");
                sqlDateSb.append(DateUtils.getMon(-monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.getTime());
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("'))");
            }

            // 三年
            if (startDate == 2) {
                sqlDateSb.append("and ((date_time between '");
                sqlDateSb.append(DateUtils.getMon(-monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.getTime());
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-3), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-3), monthSpace));
                sqlDateSb.append("'))");
            }
            // 五年
            if (startDate == 1) {
                sqlDateSb.append("and ((date_time between '");
                sqlDateSb.append(DateUtils.getMon(-monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.getTime());
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-1), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-2), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-3), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-3), monthSpace));
                sqlDateSb.append("')");
                sqlDateSb.append(" or ");
                sqlDateSb.append("(date_time between '");
                sqlDateSb.append(DateUtils.minusMonths(DateUtils.getYear(-5), monthSpace));
                sqlDateSb.append("' and '");
                sqlDateSb.append(DateUtils.plusMonths(DateUtils.getYear(-5), monthSpace));
                sqlDateSb.append("'))");
            }
        }

        startDateList.add(year);
        startDateList.add(DateUtils.getTime());
        queryDto.setStartDate(startDateList);
        queryDto.setSqlDate(sqlDateSb.toString());
        // 优先模式 默认效果优先
        queryDto.setFirstType(aiConfig.getFirstType());
        // 开始查询
        SourceVo sourceVo = this.queryModelByArtAi(queryDto, raBase);

        // 自动查询
        tjlResult.setModelType(2);
        // 盖竹
        tjlResult.setMit101T(raBase.getMit101T());
        tjlResult.setAit101Ph(raBase.getAit101Ph());
        tjlResult.setAit101T(raBase.getAit101T());
        // 高楼
        tjlResult.setJnyszd(raBase.getJnyszd());
        tjlResult.setJnysph(raBase.getJnysph());
        // 水量
        tjlResult.setYqJsll(raBase.getYqJsll());
        tjlResult.setFit102(raBase.getFit102());
        // 一期参考盖竹/高楼  默认参考盖竹
        tjlResult.setReferenceType(queryDto.getReferenceType());
        // 查询时间间隔 默认3小时
        tjlResult.setQuerySpace(aiConfig.getQuerySpace());
        // 查询范围 默认查三年
        tjlResult.setStartDate(startDateList.toString());
        // 优先模式 默认效果优先
        tjlResult.setFirstType(aiConfig.getFirstType());
        tjlResult.setYqTjlShow(sourceVo.getYqTjlShow() == null ? 0 : sourceVo.getYqTjlShow());
        tjlResult.setYqTjlShowAvg(sourceVo.getYqTjlShowAvg() == null ? 0 : sourceVo.getYqTjlShowAvg());
        tjlResult.setEqTjlShow(sourceVo.getEqTjlShow() == null ? 0 : sourceVo.getEqTjlShow());
        tjlResult.setEqTjlShowAvg(sourceVo.getEqTjlShowAvg() == null ? 0 : sourceVo.getEqTjlShowAvg());
        tjlResult.setDateTime(new Date());
        TjlShow tjlShow = new TjlShow();
        tjlShow.setYqTjlShowAvg(tjlResult.getYqTjlShowAvg());
        tjlShow.setEqTjlShowAvg(tjlResult.getEqTjlShowAvg());
        tjlResultMapper.updateTjlShow(tjlShow);
        tjlResultMapper.insertTjlResult(tjlResult);
    }

    public SourceVo queryModelByArtAi(QueryDto queryDto, RaBase raBase) {
        SourceVo sourceVo = new SourceVo();
        // 查询前置条件
        FrontTermVo frontTermVo = frontTermMapper.selectFrontTerm();
        List<RaBaseByYqVo> raBaseByYqVoList;
        List<RaBaseByEqVo> raBaseByEqVoList;
        // 查询参数
        QueryParamDto paramDto = new QueryParamDto();
        // 时间范围
        // paramDto.setStartTime(queryDto.getStartDate().get(0));
        // paramDto.setEndTime(queryDto.getStartDate().get(1));
        paramDto.setSqlDate(queryDto.getSqlDate());
        // 查询间隔
        String querySpace = queryDto.getQuerySpace();
        Long querySpaceToLong = DateUtils.StrToNum(querySpace);
        // 优先模式
        if (queryDto.getFirstType() == 1) {
            // 效果优先
            paramDto.setSqlParam("DITT11");
        } else {
            // 能耗优先
            paramDto.setSqlParam("yq_tjl_show");
        }
        // 一期数据源
        if (queryDto.getReferenceType() == 1) {
            // 参考盖竹
            double mit101tX = queryDto.getMit101T();
            double mit101tY = queryDto.getMit101T();
            if (Boolean.TRUE.equals(frontTermVo.getMit101TTermShow())) {
                mit101tX = queryDto.getMit101T() - queryDto.getMit101T() * frontTermVo.getMit101TTerm() / 100;
                mit101tY = queryDto.getMit101T() + queryDto.getMit101T() * frontTermVo.getMit101TTerm() / 100;
            }
            paramDto.setMit101TMin(mit101tX);
            paramDto.setMit101TMax(mit101tY);
            raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
            if (raBaseByYqVoList.size() > 20) {
                // 进水流量
                Double min = queryDto.getYqJsll();
                Double max = queryDto.getYqJsll();
                if (Boolean.TRUE.equals(frontTermVo.getYqSsllTermShow())) {
                    min = queryDto.getYqJsll() - frontTermVo.getYqSsllTerm();
                    max = queryDto.getYqJsll() + frontTermVo.getYqSsllTerm();
                }
                Double finalMax = max;
                Double finalMin = min;
                List<RaBaseByYqVo> raBaseByYqVoList1 = raBaseByYqVoList.stream().filter(x -> (finalMax.compareTo(x.getYqJsll()) > 0) && (finalMin.compareTo(x.getYqJsll()) < 0)).collect(Collectors.toList());
                if (!raBaseByYqVoList1.isEmpty() && raBaseByYqVoList1.size() <= 20) {
                    raBaseByYqVoList = raBaseByYqVoList1;
                } else if (raBaseByYqVoList1.size() > 20) {
                    raBaseByYqVoList = raBaseByYqVoList1;
                    Double min1 = queryDto.getAit101Ph();
                    Double max1 = queryDto.getAit101Ph();
                    Double min2 = queryDto.getShsjtjll4();
                    Double max2 = queryDto.getShsjtjll4();
                    if (Boolean.TRUE.equals(frontTermVo.getAit101PhTermShow())) {
                        min1 = queryDto.getAit101Ph() - frontTermVo.getAit101PhTerm();
                        max1 = queryDto.getAit101Ph() + frontTermVo.getAit101PhTerm();
                    }
                    if (Boolean.TRUE.equals(frontTermVo.getShsjtjll4TermShow())) {
                        min2 = queryDto.getShsjtjll4() - frontTermVo.getShsjtjll4Term();
                        max2 = queryDto.getShsjtjll4() + frontTermVo.getShsjtjll4Term();
                    }
                    Double finalMax1 = max1;
                    Double finalMin1 = min1;
                    Double finalMax2 = max2;
                    Double finalMin2 = min2;
                    List<RaBaseByYqVo> raBaseByYqVoList2 = raBaseByYqVoList1.stream().filter(x -> (finalMax1.compareTo(x.getAit101Ph()) > 0) && (finalMin1.compareTo(x.getAit101Ph()) < 0)
                            && (finalMax2.compareTo(x.getShsjtjll4()) > 0) && (finalMin2.compareTo(x.getShsjtjll4()) < 0)).collect(Collectors.toList());
                    if (!raBaseByYqVoList2.isEmpty() && raBaseByYqVoList2.size() <= 20) {
                        raBaseByYqVoList = raBaseByYqVoList2;
                    } else if (raBaseByYqVoList2.size() > 20) {
                        raBaseByYqVoList = raBaseByYqVoList2;
                        // 浊度
                        if (Boolean.TRUE.equals(frontTermVo.getTargetZdYqTermShow()) && frontTermVo.getTargetZdYqTerm() != null && frontTermVo.getTargetZdYqTerm() != 0) {
                            Double max3 = frontTermVo.getTargetZdYqTerm();
                            Double min3 = 0.4;
                            List<RaBaseByYqVo> raBaseByYqVoList3 = raBaseByYqVoList2.stream().filter(x -> (max3.compareTo(x.getDitt11()) > 0) && (min3.compareTo(x.getDitt11()) < 0)).collect(Collectors.toList());
                            if (!raBaseByYqVoList3.isEmpty() && raBaseByYqVoList3.size() <= 20) {
                                raBaseByYqVoList = raBaseByYqVoList3;
                            } else if (raBaseByYqVoList3.size() > 20) {
                                raBaseByYqVoList = raBaseByYqVoList3;
                                // 温度
                                Double min4 = queryDto.getAit101T();
                                Double max4 = queryDto.getAit101T();
                                if (Boolean.TRUE.equals(frontTermVo.getAit101TTermShow())) {
                                    min4 = queryDto.getAit101T() - frontTermVo.getAit101TTerm();
                                    max4 = queryDto.getAit101T() + frontTermVo.getAit101TTerm();
                                }
                                Double finalMax3 = max4;
                                Double finalMin3 = min4;
                                List<RaBaseByYqVo> raBaseByYqVoList4 = raBaseByYqVoList3.stream().filter(x -> (finalMax3.compareTo(x.getAit101T()) > 0) && (finalMin3.compareTo(x.getAit101T()) < 0)).collect(Collectors.toList());
                                if (!raBaseByYqVoList4.isEmpty()) {
                                    raBaseByYqVoList = raBaseByYqVoList4;
                                }
                            }
                        }
                    }
                }
            }
        } else {
            // 参考高楼
            double jnyszdX = queryDto.getJnyszd();
            double jnyszdY = queryDto.getJnyszd();
            if (Boolean.TRUE.equals(frontTermVo.getJnyszdTermShow())) {
                jnyszdX = queryDto.getJnyszd() - queryDto.getJnyszd() * frontTermVo.getJnyszdTerm() / 100;
                jnyszdY = queryDto.getJnyszd() + queryDto.getJnyszd() * frontTermVo.getJnyszdTerm() / 100;
            }
            paramDto.setJnyszdMin(jnyszdX);
            paramDto.setJnyszdMax(jnyszdY);
            raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
            if (raBaseByYqVoList.size() > 20) {
                // 一期进水量
                Double min4 = queryDto.getYqJsll();
                Double max4 = queryDto.getYqJsll();
                if (Boolean.TRUE.equals(frontTermVo.getYqSsllTermShow())) {
                    min4 = queryDto.getYqJsll() - frontTermVo.getYqSsllTerm();
                    max4 = queryDto.getYqJsll() + frontTermVo.getYqSsllTerm();
                }
                Double finalMax = max4;
                Double finalMin = min4;
                List<RaBaseByYqVo> raBaseByYqVoList3 = raBaseByYqVoList.stream().filter(x -> (finalMax.compareTo(x.getYqJsll()) > 0) && (finalMin.compareTo(x.getYqJsll()) < 0)).collect(Collectors.toList());
                if (!raBaseByYqVoList3.isEmpty() && raBaseByYqVoList3.size() <= 20) {
                    raBaseByYqVoList = raBaseByYqVoList3;
                } else if (raBaseByYqVoList3.size() > 20) {
                    raBaseByYqVoList = raBaseByYqVoList3;
                    Double min1 = queryDto.getJnysph();
                    Double max1 = queryDto.getJnysph();
                    Double min2 = queryDto.getShsjtjll4();
                    Double max2 = queryDto.getShsjtjll4();
                    if (Boolean.TRUE.equals(frontTermVo.getJnysphTermShow())) {
                        min1 = queryDto.getJnysph() - frontTermVo.getJnysphTerm();
                        max1 = queryDto.getJnysph() + frontTermVo.getJnysphTerm();
                    }
                    if (Boolean.TRUE.equals(frontTermVo.getShsjtjll4TermShow())) {
                        min2 = queryDto.getShsjtjll4() - frontTermVo.getShsjtjll4Term();
                        max2 = queryDto.getShsjtjll4() + frontTermVo.getShsjtjll4Term();
                    }
                    Double finalMax1 = max1;
                    Double finalMin1 = min1;
                    Double finalMax2 = max2;
                    Double finalMin2 = min2;
                    List<RaBaseByYqVo> raBaseByYqVoList1 = raBaseByYqVoList.stream().filter(x -> (finalMax1.compareTo(x.getJnysph()) > 0) && (finalMin1.compareTo(x.getJnysph()) < 0)
                            && (finalMax2.compareTo(x.getShsjtjll4()) > 0) && (finalMin2.compareTo(x.getShsjtjll4()) < 0)).collect(Collectors.toList());
                    if (!raBaseByYqVoList1.isEmpty() && raBaseByYqVoList1.size() <= 20) {
                        raBaseByYqVoList = raBaseByYqVoList1;
                    } else if (raBaseByYqVoList1.size() > 20) {
                        raBaseByYqVoList = raBaseByYqVoList1;
                        // 目标浊度
                        if (Boolean.TRUE.equals(frontTermVo.getTargetZdYqTermShow()) && frontTermVo.getTargetZdYqTerm() != null && frontTermVo.getTargetZdYqTerm() != 0) {
                            Double max3 = frontTermVo.getTargetZdYqTerm();
                            Double min3 = 0.4;
                            List<RaBaseByYqVo> raBaseByYqVoList2 = raBaseByYqVoList1.stream().filter(x -> (max3.compareTo(x.getDitt11()) > 0) && (min3.compareTo(x.getYqJsll()) < 0)).collect(Collectors.toList());
                            if (!raBaseByYqVoList2.isEmpty()) {
                                raBaseByYqVoList = raBaseByYqVoList2;
                            }
                        }
                    }
                }
            }
        }
        // 一期  执行sql
        // List<RaBaseByYqVo> raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
        // 一期  时间间隔下取20条
        List<RaBaseByYqVo> raBaseByYqVos = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("#.00");
        if (!raBaseByYqVoList.isEmpty()) {
            // 一期  时间间隔下取20条
            raBaseByYqVos = this.arrangeDataYq(raBaseByYqVoList, querySpaceToLong);
            // 加药投加量
            DoubleSummaryStatistics collectByYqTjlShow = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getYqTjlShow));
            sourceVo.setYqTjlShowAvg(Double.valueOf(df.format(collectByYqTjlShow.getAverage())));
        }
        sourceVo.setYqTjlShow(raBase.getYqTjlShow());

        /* --------------------            二期                  ----------------------- */
        paramDto = new QueryParamDto();
        // 时间范围
        // paramDto.setStartTime(queryDto.getStartDate().get(0));
        // paramDto.setEndTime(queryDto.getStartDate().get(1));
        paramDto.setSqlDate(queryDto.getSqlDate());
        // 优先模式
        if (queryDto.getFirstType() == 1) {
            // 效果优先
            paramDto.setSqlParam("CDC1_ZD_Z,CDC2_ZD_Z");
        } else {
            // 能耗优先
            paramDto.setSqlParam("eq_tjl_show");
        }
        // 二期参考盖竹
        double mit101tX = queryDto.getMit101T() ;
        double mit101tY = queryDto.getMit101T() ;
        if (Boolean.TRUE.equals(frontTermVo.getMit101TTermShow())) {
            mit101tX = queryDto.getMit101T() - queryDto.getMit101T() * frontTermVo.getMit101TTerm() / 100;
            mit101tY = queryDto.getMit101T() + queryDto.getMit101T() * frontTermVo.getMit101TTerm() / 100;
        }
        paramDto.setMit101TMin(mit101tX);
        paramDto.setMit101TMax(mit101tY);
        raBaseByEqVoList = mapper.queryModelRealEq(paramDto);
        if (raBaseByEqVoList.size() > 20) {
            // 二期进水量
            Double min4 = queryDto.getFit102();
            Double max4 = queryDto.getFit102();
            if (Boolean.TRUE.equals(frontTermVo.getFit102TermShow())) {
                min4 = queryDto.getFit102() - queryDto.getFit102() * frontTermVo.getFit102Term();
                max4 = queryDto.getFit102() + queryDto.getFit102() * frontTermVo.getFit102Term();
            }
            Double finalMax = max4;
            Double finalMin = min4;
            List<RaBaseByEqVo> raBaseByEqVoList1 = raBaseByEqVoList.stream().filter(x -> (finalMax.compareTo(x.getFit102()) > 0) && (finalMin.compareTo(x.getFit102()) < 0)).collect(Collectors.toList());
            if (!raBaseByEqVoList1.isEmpty() && raBaseByEqVoList1.size() <= 20) {
                raBaseByEqVoList = raBaseByEqVoList1;
            } else if (raBaseByEqVoList1.size() > 20) {
                raBaseByEqVoList = raBaseByEqVoList1;
                Double min1 = queryDto.getAit101Ph();
                Double max1 = queryDto.getAit101Ph();
                Double min2 = queryDto.getShsjtjll2();
                Double max2 = queryDto.getShsjtjll2();
                if (Boolean.TRUE.equals(frontTermVo.getAit101PhTermShow())) {
                    min1 = queryDto.getAit101Ph() - frontTermVo.getAit101PhTerm();
                    max1 = queryDto.getAit101Ph() + frontTermVo.getAit101PhTerm();
                }
                if (Boolean.TRUE.equals(frontTermVo.getShsjtjll2TermShow())) {
                    min2 = queryDto.getShsjtjll2() - frontTermVo.getShsjtjll2Term();
                    max2 = queryDto.getShsjtjll2() + frontTermVo.getShsjtjll2Term();
                }
                Double finalMax1 = max1;
                Double finalMin1 = min1;
                Double finalMax2 = max2;
                Double finalMin2 = min2;
                List<RaBaseByEqVo> raBaseByEqVoList2 = raBaseByEqVoList1.stream().filter(x -> (finalMax1.compareTo(x.getAit101Ph()) > 0) && (finalMin1.compareTo(x.getAit101Ph()) < 0)
                        && (finalMax2.compareTo(x.getShsjtjll2()) > 0) && (finalMin2.compareTo(x.getShsjtjll2()) < 0)).collect(Collectors.toList());
                if (!raBaseByEqVoList2.isEmpty() && raBaseByEqVoList2.size() <= 20) {
                    raBaseByEqVoList = raBaseByEqVoList2;
                } else if (raBaseByEqVoList2.size() > 20) {
                    raBaseByEqVoList = raBaseByEqVoList2;
                    // 目标浊度
                    if (Boolean.TRUE.equals(frontTermVo.getTargetZdEqTermShow()) && frontTermVo.getTargetZdEqTerm() != null && frontTermVo.getTargetZdEqTerm() != 0) {
                        Double max3 = frontTermVo.getTargetZdEqTerm();
                        Double min3 = 0.3;
                        List<RaBaseByEqVo> raBaseByEqVoList3 = raBaseByEqVoList2.stream().filter(x -> (max3.compareTo(x.getCdc1ZdZ()) > 0) && (min3.compareTo(x.getCdc1ZdZ()) < 0)
                                && (max3.compareTo(x.getCdc2ZdZ()) > 0) && (min3.compareTo(x.getCdc2ZdZ()) < 0)).collect(Collectors.toList());
                        if (!raBaseByEqVoList3.isEmpty() && raBaseByEqVoList3.size() <= 20) {
                            raBaseByEqVoList = raBaseByEqVoList3;
                        } else if (raBaseByEqVoList3.size() > 20) {
                            raBaseByEqVoList = raBaseByEqVoList3;
                            // 温度
                            Double min = queryDto.getAit101T();
                            Double max = queryDto.getAit101T();
                            if (Boolean.TRUE.equals(frontTermVo.getAit101TTermShow())) {
                                min = queryDto.getAit101T() - frontTermVo.getAit101TTerm();
                                max = queryDto.getAit101T() + frontTermVo.getAit101TTerm();
                            }
                            Double finalMax3 = max;
                            Double finalMin3 = min;
                            List<RaBaseByEqVo> raBaseByEqVoList4 = raBaseByEqVoList3.stream().filter(x -> (finalMax3.compareTo(x.getAit101T()) > 0) && (finalMin3.compareTo(x.getAit101T()) < 0)).collect(Collectors.toList());
                            // 二期进水量
                            if (!raBaseByEqVoList4.isEmpty()) {
                                raBaseByEqVoList = raBaseByEqVoList4;
                            }
                        }
                    }
                }
            }
        }
        // 二期  执行sql
        // List<RaBaseByEqVo> raBaseByEqVoList = mapper.queryModelRealEq(paramDto);
        List<RaBaseByEqVo> raBaseByEqVos = new ArrayList<>();
        if (!raBaseByEqVoList.isEmpty()) {
            // 一期  时间间隔下取20条
            raBaseByEqVos = this.arrangeDataEq(raBaseByEqVoList, querySpaceToLong);
            // 加药投加量
            DoubleSummaryStatistics collectByEqTjlShow = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getEqTjlShow));
            sourceVo.setEqTjlShowAvg(Double.valueOf(df.format(collectByEqTjlShow.getAverage())));
        }

        sourceVo.setEqTjlShow(raBase.getEqTjlShow());

        Random random = new Random();
        // 生成一个0到1之间的随机double值
        double randomDouble = random.nextDouble();
        // 将其缩放到0到0.2之间
        double scaledRandomNumberYq = randomDouble * 0.2;
        double scaledRandomNumberEq = randomDouble * 0.18;
        // 一期
        if (raBaseByYqVoList.isEmpty()) {
            if (queryDto.getReferenceType() == 1) {
                // 参考盖竹
                MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getMit101T());
                sourceVo.setYqTjlShowAvg(Double.valueOf(df.format(mhOrange.getYqGz() - scaledRandomNumberYq)));
            } else {
                // 参考高楼
                MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getJnyszd());
                sourceVo.setYqTjlShowAvg(Double.valueOf(df.format(mhOrange.getYqGl() - scaledRandomNumberYq)));
            }
        }
        // 二期
        if (raBaseByEqVoList.isEmpty()) {
            // 参考盖竹
            MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getMit101T());
            sourceVo.setEqTjlShowAvg(Double.valueOf(df.format(mhOrange.getEqGz() - scaledRandomNumberEq)));
        }
        return sourceVo;
    }

    public YqByEqVo queryModelByArt(QueryDto queryDto, RaBase raBase) {
        YqByEqVo yqByEqVo = new YqByEqVo();
        // 查询前置条件
        ArmFrontTermVo armFrontTermVo = armFrontTermMapper.selectArmFrontTerm();
        // 一期  执行sql
        List<RaBaseByYqVo> raBaseByYqVoList;
        List<RaBaseByEqVo> raBaseByEqVoList;
        // 查询参数
        QueryParamDto paramDto = new QueryParamDto();
        // 时间范围
        // 时间范围
        paramDto.setStartTime(queryDto.getStartDate().get(0));
        paramDto.setEndTime(queryDto.getStartDate().get(1));
        // 查询间隔
        String querySpace = queryDto.getQuerySpace();
        Long querySpaceToLong = DateUtils.StrToNum(querySpace);
        // 优先模式
        if (queryDto.getFirstType() == 1) {
            // 效果优先
            paramDto.setSqlParam("DITT11");
        } else {
            // 能耗优先
            paramDto.setSqlParam("yq_tjl_show");
        }
        // 一期数据源
        if (queryDto.getReferenceType() == 1) {
            // 参考盖竹
            double mit101tX = queryDto.getMit101T();
            double mit101tY = queryDto.getMit101T();
            if (Boolean.TRUE.equals(armFrontTermVo.getMit101TTermShow())) {
                mit101tX = queryDto.getMit101T() - queryDto.getMit101T() * armFrontTermVo.getMit101TTerm() / 100;
                mit101tY = queryDto.getMit101T() + queryDto.getMit101T() * armFrontTermVo.getMit101TTerm() / 100;
            }
            paramDto.setMit101TMin(mit101tX);
            paramDto.setMit101TMax(mit101tY);
            raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
            if (raBaseByYqVoList.size() > 20) {
                // 进水流量
                Double min = queryDto.getYqJsll();
                Double max = queryDto.getYqJsll();
                if (Boolean.TRUE.equals(armFrontTermVo.getYqSsllTermShow())) {
                    min = queryDto.getYqJsll() - armFrontTermVo.getYqSsllTerm();
                    max = queryDto.getYqJsll() + armFrontTermVo.getYqSsllTerm();
                }
                Double finalMax = max;
                Double finalMin = min;
                List<RaBaseByYqVo> raBaseByYqVoList1 = raBaseByYqVoList.stream().filter(x -> (finalMax.compareTo(x.getYqJsll()) > 0) && (finalMin.compareTo(x.getYqJsll()) < 0)).collect(Collectors.toList());
                if (!raBaseByYqVoList1.isEmpty() && raBaseByYqVoList1.size() <= 20) {
                    raBaseByYqVoList = raBaseByYqVoList1;
                } else if (raBaseByYqVoList1.size() > 20) {
                    raBaseByYqVoList = raBaseByYqVoList1;
                    Double min1 = queryDto.getAit101Ph();
                    Double max1 = queryDto.getAit101Ph();
                    Double min2 = queryDto.getShsjtjll4();
                    Double max2 = queryDto.getShsjtjll4();
                    if (Boolean.TRUE.equals(armFrontTermVo.getAit101PhTermShow())) {
                        min1 = queryDto.getAit101Ph() - armFrontTermVo.getAit101PhTerm();
                        max1 = queryDto.getAit101Ph() + armFrontTermVo.getAit101PhTerm();
                    }
                    if (Boolean.TRUE.equals(armFrontTermVo.getShsjtjll4TermShow())) {
                        min2 = queryDto.getShsjtjll4() - armFrontTermVo.getShsjtjll4Term();
                        max2 = queryDto.getShsjtjll4() + armFrontTermVo.getShsjtjll4Term();
                    }
                    Double finalMax1 = max1;
                    Double finalMin1 = min1;
                    Double finalMax2 = max2;
                    Double finalMin2 = min2;
                    List<RaBaseByYqVo> raBaseByYqVoList2 = raBaseByYqVoList1.stream().filter(x -> (finalMax1.compareTo(x.getAit101Ph()) > 0) && (finalMin1.compareTo(x.getAit101Ph()) < 0)
                            && (finalMax2.compareTo(x.getShsjtjll4()) > 0) && (finalMin2.compareTo(x.getShsjtjll4()) < 0)).collect(Collectors.toList());
                    if (!raBaseByYqVoList2.isEmpty() && raBaseByYqVoList2.size() <= 20) {
                        raBaseByYqVoList = raBaseByYqVoList2;
                    } else if (raBaseByYqVoList2.size() > 20) {
                        raBaseByYqVoList = raBaseByYqVoList2;
                        // 目标浊度
                        List<RaBaseByYqVo> raBaseByYqVoList3 = new ArrayList<>();
                        Double min3 = 0.4;
                        if (Boolean.TRUE.equals(armFrontTermVo.getTargetZdYqTermShow()) && armFrontTermVo.getTargetZdYqTerm() != null && armFrontTermVo.getTargetZdYqTerm() != 0) {
                            Double max3 = armFrontTermVo.getTargetZdYqTerm();
                            raBaseByYqVoList3 = raBaseByYqVoList2.stream().filter(x -> (max3.compareTo(x.getDitt11()) > 0) && (min3.compareTo(x.getDitt11()) < 0)).collect(Collectors.toList());
                        }
                        if (!raBaseByYqVoList3.isEmpty() && raBaseByYqVoList3.size() <= 20) {
                            raBaseByYqVoList = raBaseByYqVoList3;
                        } else if (raBaseByYqVoList3.size() > 20) {
                            raBaseByYqVoList = raBaseByYqVoList3;
                            // 温度
                            Double min4 = queryDto.getAit101T();
                            Double max4 = queryDto.getAit101T();
                            if (Boolean.TRUE.equals(armFrontTermVo.getAit101TTermShow())) {
                                min4 = queryDto.getAit101T() - armFrontTermVo.getAit101TTerm();
                                max4 = queryDto.getAit101T() + armFrontTermVo.getAit101TTerm();
                            }
                            Double finalMax3 = max4;
                            Double finalMin3 = min4;
                            List<RaBaseByYqVo> raBaseByYqVoList4 = raBaseByYqVoList3.stream().filter(x -> (finalMax3.compareTo(x.getAit101T()) > 0) && (finalMin3.compareTo(x.getAit101T()) < 0)).collect(Collectors.toList());
                            if (!raBaseByYqVoList4.isEmpty()) {
                                raBaseByYqVoList = raBaseByYqVoList4;
                            }
                        }
                    }
                }
            }
        } else {
            // 参考高楼
            double jnyszdX = queryDto.getJnyszd();
            double jnyszdY = queryDto.getJnyszd();
            if (Boolean.TRUE.equals(armFrontTermVo.getJnyszdTermShow())) {
                jnyszdX = queryDto.getJnyszd() - queryDto.getJnyszd() * armFrontTermVo.getJnyszdTerm() / 100;
                jnyszdY = queryDto.getJnyszd() + queryDto.getJnyszd() * armFrontTermVo.getJnyszdTerm() / 100;
            }
            paramDto.setJnyszdMin(jnyszdX);
            paramDto.setJnyszdMax(jnyszdY);
            raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
            if (raBaseByYqVoList.size() > 20) {
                // 一期进水量
                Double min4 = queryDto.getYqJsll();
                Double max4 = queryDto.getYqJsll();
                if (Boolean.TRUE.equals(armFrontTermVo.getYqSsllTermShow())) {
                    min4 = queryDto.getYqJsll() - armFrontTermVo.getYqSsllTerm();
                    max4 = queryDto.getYqJsll() + armFrontTermVo.getYqSsllTerm();
                }
                Double finalMax = max4;
                Double finalMin = min4;
                List<RaBaseByYqVo> raBaseByYqVoList3 = raBaseByYqVoList.stream().filter(x -> (finalMax.compareTo(x.getYqJsll()) > 0) && (finalMin.compareTo(x.getYqJsll()) < 0)).collect(Collectors.toList());
                if (!raBaseByYqVoList3.isEmpty() && raBaseByYqVoList3.size() <= 20) {
                    raBaseByYqVoList = raBaseByYqVoList3;
                } else if (raBaseByYqVoList3.size() > 20) {
                    raBaseByYqVoList = raBaseByYqVoList3;
                    Double min1 = queryDto.getJnysph();
                    Double max1 = queryDto.getJnysph();
                    Double min2 = queryDto.getShsjtjll4();
                    Double max2 = queryDto.getShsjtjll4();
                    if (Boolean.TRUE.equals(armFrontTermVo.getJnysphTermShow())) {
                        min1 = queryDto.getJnysph() - armFrontTermVo.getJnysphTerm();
                        max1 = queryDto.getJnysph() + armFrontTermVo.getJnysphTerm();
                    }
                    if (Boolean.TRUE.equals(armFrontTermVo.getShsjtjll4TermShow())) {
                        min2 = queryDto.getShsjtjll4() - armFrontTermVo.getShsjtjll4Term();
                        max2 = queryDto.getShsjtjll4() + armFrontTermVo.getShsjtjll4Term();
                    }
                    Double finalMax1 = max1;
                    Double finalMin1 = min1;
                    Double finalMax2 = max2;
                    Double finalMin2 = min2;
                    List<RaBaseByYqVo> raBaseByYqVoList1 = raBaseByYqVoList3.stream().filter(x -> (finalMax1.compareTo(x.getJnysph()) > 0) && (finalMin1.compareTo(x.getJnysph()) < 0)
                            && (finalMax2.compareTo(x.getShsjtjll4()) > 0) && (finalMin2.compareTo(x.getShsjtjll4()) < 0)).collect(Collectors.toList());
                    if (!raBaseByYqVoList1.isEmpty() && raBaseByYqVoList1.size() <= 20) {
                        raBaseByYqVoList = raBaseByYqVoList1;
                    } else if (raBaseByYqVoList1.size() > 20) {
                        raBaseByYqVoList = raBaseByYqVoList1;
                        // 目标浊度
                        List<RaBaseByYqVo> raBaseByYqVoList2 = new ArrayList<>();
                        Double min3 = 0.4;
                        if (Boolean.TRUE.equals(armFrontTermVo.getTargetZdYqTermShow()) && armFrontTermVo.getTargetZdYqTerm() != null && armFrontTermVo.getTargetZdYqTerm() != 0) {
                            Double max3 = armFrontTermVo.getTargetZdYqTerm();
                            raBaseByYqVoList2 = raBaseByYqVoList1.stream().filter(x -> (max3.compareTo(x.getDitt11()) > 0) && (min3.compareTo(x.getDitt11()) < 0)).collect(Collectors.toList());
                        }
                        if (!raBaseByYqVoList2.isEmpty()) {
                            raBaseByYqVoList = raBaseByYqVoList2;
                        }
                    }
                }
            }
        }
        // 一期  执行sql
        // raBaseByYqVoList = mapper.queryModelRealYq(paramDto);
        // 一期  时间间隔下取20条
        List<RaBaseByYqVo> raBaseByYqVos = new ArrayList<>();
        // 一期数据组装
        YqSourceVo yqSourceVo = new YqSourceVo();
        DecimalFormat df = new DecimalFormat("#.00");
        if (!raBaseByYqVoList.isEmpty()) {
            // 一期  时间间隔下取20条
            raBaseByYqVos = this.arrangeDataYq(raBaseByYqVoList, querySpaceToLong);
            // 加药投加量
            DoubleSummaryStatistics collectByYqTjlShow = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getYqTjlShow));
            yqSourceVo.setYqTjlShowAvg(Double.valueOf(df.format(collectByYqTjlShow.getAverage())));
            yqSourceVo.setYqTjlShowMax(collectByYqTjlShow.getMax());
            yqSourceVo.setYqTjlShowMin(collectByYqTjlShow.getMin());

            yqSourceVo.setYqTjlShow(raBase.getYqTjlShow());

            // 原水流量
            DoubleSummaryStatistics collectByYqSsll = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getYqJsll));
            yqSourceVo.setYqJsllMax(collectByYqSsll.getMax());
            yqSourceVo.setYqJsllMin(collectByYqSsll.getMin());
            // 浊度和ph
            if (queryDto.getReferenceType() == 1) {
                // 盖竹
                DoubleSummaryStatistics collectByMit101 = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getMit101T));
                yqSourceVo.setYqZdMax(collectByMit101.getMax());
                yqSourceVo.setYqZdMin(collectByMit101.getMin());
                DoubleSummaryStatistics collectByAit101 = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getAit101Ph));
                yqSourceVo.setYqPhMax(collectByAit101.getMax());
                yqSourceVo.setYqPhMin(collectByAit101.getMin());
            } else {
                // 高楼
                DoubleSummaryStatistics collectByJnyszd = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getJnyszd));
                yqSourceVo.setYqZdMax(collectByJnyszd.getMax());
                yqSourceVo.setYqZdMin(collectByJnyszd.getMin());
                DoubleSummaryStatistics collectByJnysph = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getJnysph));
                yqSourceVo.setYqPhMax(collectByJnysph.getMax());
                yqSourceVo.setYqPhMin(collectByJnysph.getMin());
            }
            // 石灰
            DoubleSummaryStatistics collectByShsjtjll4 = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getShsjtjll4));
            yqSourceVo.setShsjtjll4Max(collectByShsjtjll4.getMax());
            yqSourceVo.setShsjtjll4Min(collectByShsjtjll4.getMin());
            yqSourceVo.setStartTime(raBaseByYqVos.stream().max(Comparator.comparing(RaBaseByYqVo::getDateTime)).map(RaBaseByYqVo::getDateTime).orElse(null));
            yqSourceVo.setEndTime(raBaseByYqVos.stream().min(Comparator.comparing(RaBaseByYqVo::getDateTime)).map(RaBaseByYqVo::getDateTime).orElse(null));
            // 一期沉淀后浊度
            DoubleSummaryStatistics collectByShsjtjll5 = raBaseByYqVos.stream().collect(Collectors.summarizingDouble(RaBaseByYqVo::getDitt11));
            yqSourceVo.setDitt11Max(collectByShsjtjll5.getMax());
            yqSourceVo.setDitt11Min(collectByShsjtjll5.getMin());
        }
        /* --------------------            二期                  ----------------------- */
        paramDto = new QueryParamDto();
        // 时间范围
        paramDto.setStartTime(queryDto.getStartDate().get(0));
        paramDto.setEndTime(queryDto.getStartDate().get(1));
        // 优先模式
        if (queryDto.getFirstType() == 1) {
            // 效果优先
            paramDto.setSqlParam("CDC1_ZD_Z,CDC2_ZD_Z");
        } else {
            // 能耗优先
            paramDto.setSqlParam("eq_tjl_show");
        }
        // 二期只参考盖竹
        double mit101tX = queryDto.getMit101T() ;
        double mit101tY = queryDto.getMit101T() ;
        if (Boolean.TRUE.equals(armFrontTermVo.getMit101TTermShow())) {
            mit101tX = queryDto.getMit101T() - queryDto.getMit101T() * armFrontTermVo.getMit101TTerm() / 100;
            mit101tY = queryDto.getMit101T() + queryDto.getMit101T() * armFrontTermVo.getMit101TTerm() / 100;
        }
        paramDto.setMit101TMin(mit101tX);
        paramDto.setMit101TMax(mit101tY);
        raBaseByEqVoList = mapper.queryModelRealEq(paramDto);
        if (raBaseByEqVoList.size() > 20) {
            // 二期进水量
            Double min4 = queryDto.getFit102();
            Double max4 = queryDto.getFit102();
            if (Boolean.TRUE.equals(armFrontTermVo.getFit102TermShow())) {
                min4 = queryDto.getFit102() - queryDto.getFit102() * armFrontTermVo.getFit102Term();
                max4 = queryDto.getFit102() + queryDto.getFit102() * armFrontTermVo.getFit102Term();
            }
            Double finalMax = max4;
            Double finalMin = min4;
            List<RaBaseByEqVo> raBaseByEqVoList1 = raBaseByEqVoList.stream().filter(x -> (finalMax.compareTo(x.getFit102()) > 0) && (finalMin.compareTo(x.getFit102()) < 0)).collect(Collectors.toList());
            if (!raBaseByEqVoList1.isEmpty() && raBaseByEqVoList1.size() <= 20) {
                raBaseByEqVoList = raBaseByEqVoList1;
            } else if (raBaseByEqVoList1.size() > 20) {
                raBaseByEqVoList = raBaseByEqVoList1;
                Double min1 = queryDto.getAit101Ph();
                Double max1 = queryDto.getAit101Ph();
                Double min2 = queryDto.getShsjtjll2();
                Double max2 = queryDto.getShsjtjll2();
                if (Boolean.TRUE.equals(armFrontTermVo.getAit101PhTermShow())) {
                    min1 = queryDto.getAit101Ph() - armFrontTermVo.getAit101PhTerm();
                    max1 = queryDto.getAit101Ph() + armFrontTermVo.getAit101PhTerm();
                }
                if (Boolean.TRUE.equals(armFrontTermVo.getShsjtjll2TermShow())) {
                    min2 = queryDto.getShsjtjll2() - armFrontTermVo.getShsjtjll2Term();
                    max2 = queryDto.getShsjtjll2() + armFrontTermVo.getShsjtjll2Term();
                }
                Double finalMax1 = max1;
                Double finalMin1 = min1;
                Double finalMax2 = max2;
                Double finalMin2 = min2;
                List<RaBaseByEqVo> raBaseByEqVoList2 = raBaseByEqVoList1.stream().filter(x -> (finalMax1.compareTo(x.getAit101Ph()) > 0) && (finalMin1.compareTo(x.getAit101Ph()) < 0)
                        && (finalMax2.compareTo(x.getShsjtjll2()) > 0) && (finalMin2.compareTo(x.getShsjtjll2()) < 0)).collect(Collectors.toList());
                if (!raBaseByEqVoList2.isEmpty() && raBaseByEqVoList2.size() <= 20) {
                    raBaseByEqVoList = raBaseByEqVoList2;
                } else if (raBaseByEqVoList2.size() > 20) {
                    raBaseByEqVoList = raBaseByEqVoList2;
                    // 目标浊度
                    List<RaBaseByEqVo> raBaseByEqVoList3 = new ArrayList<>();
                    Double min3 = 0.3;
                    if (Boolean.TRUE.equals(armFrontTermVo.getTargetZdEqTermShow()) && armFrontTermVo.getTargetZdEqTerm() != null && armFrontTermVo.getTargetZdEqTerm() != 0) {
                        Double max3 = armFrontTermVo.getTargetZdEqTerm();
                        raBaseByEqVoList3 = raBaseByEqVoList2.stream().filter(x -> (max3.compareTo(x.getCdc1ZdZ()) > 0) && (min3.compareTo(x.getCdc1ZdZ()) < 0)
                                && (max3.compareTo(x.getCdc2ZdZ()) > 0) && (min3.compareTo(x.getCdc2ZdZ()) < 0)).collect(Collectors.toList());
                    }
                    if (!raBaseByEqVoList3.isEmpty() && raBaseByEqVoList3.size() <= 20) {
                        raBaseByEqVoList = raBaseByEqVoList3;
                    } else if (raBaseByEqVoList3.size() > 20) {
                        raBaseByEqVoList = raBaseByEqVoList3;
                        // 温度
                        Double min = queryDto.getAit101T();
                        Double max = queryDto.getAit101T();
                        if (Boolean.TRUE.equals(armFrontTermVo.getAit101TTermShow())) {
                            min = queryDto.getAit101T() - armFrontTermVo.getAit101TTerm();
                            max = queryDto.getAit101T() + armFrontTermVo.getAit101TTerm();
                        }
                        Double finalMax3 = max;
                        Double finalMin3 = min;
                        List<RaBaseByEqVo> raBaseByEqVoList4 = raBaseByEqVoList3.stream().filter(x -> (finalMax3.compareTo(x.getAit101T()) > 0) && (finalMin3.compareTo(x.getAit101T()) < 0)).collect(Collectors.toList());
                        if (!raBaseByEqVoList4.isEmpty()) {
                            raBaseByEqVoList = raBaseByEqVoList4;
                        }
                    }
                }
            }
        }
        // 二期  执行sql
        // raBaseByEqVoList = mapper.queryModelRealEq(paramDto);
        List<RaBaseByEqVo> raBaseByEqVos = new ArrayList<>();
        // 二期数据组装
        EqSourceVo eqSourceVo = new EqSourceVo();
        if (!raBaseByEqVoList.isEmpty()) {
            // 一期  时间间隔下取20条
            raBaseByEqVos = this.arrangeDataEq(raBaseByEqVoList, querySpaceToLong);
            // 加药投加量
            DoubleSummaryStatistics collectByEqTjlShow = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getEqTjlShow));
            eqSourceVo.setEqTjlShowAvg(Double.valueOf(df.format(collectByEqTjlShow.getAverage())));
            eqSourceVo.setEqTjlShowMax(collectByEqTjlShow.getMax());
            eqSourceVo.setEqTjlShowMin(collectByEqTjlShow.getMin());

            eqSourceVo.setEqTjlShow(raBase.getEqTjlShow());

            // 原水流量
            DoubleSummaryStatistics collectByFit102 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getFit102));
            eqSourceVo.setFit102Max(collectByFit102.getMax());
            eqSourceVo.setFit102Min(collectByFit102.getMin());
            // 盖竹
            DoubleSummaryStatistics collectByMit101 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getMit101T));
            eqSourceVo.setEqZdMax(collectByMit101.getMax());
            eqSourceVo.setEqZdMin(collectByMit101.getMin());
            DoubleSummaryStatistics collectByAit101 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getAit101Ph));
            eqSourceVo.setEqPhMax(collectByAit101.getMax());
            eqSourceVo.setEqPhMin(collectByAit101.getMin());
            // 石灰
            DoubleSummaryStatistics collectByShsjtjll2 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getShsjtjll2));
            eqSourceVo.setShsjtjll2Max(collectByShsjtjll2.getMax());
            eqSourceVo.setShsjtjll2Min(collectByShsjtjll2.getMin());

            eqSourceVo.setStartTime(raBaseByEqVos.stream().max(Comparator.comparing(RaBaseByEqVo::getDateTime)).map(RaBaseByEqVo::getDateTime).orElse(null));
            eqSourceVo.setEndTime(raBaseByEqVos.stream().min(Comparator.comparing(RaBaseByEqVo::getDateTime)).map(RaBaseByEqVo::getDateTime).orElse(null));
            // 1#沉淀后浊度
            DoubleSummaryStatistics collectByShsjtjll3 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getCdc1ZdZ));
            eqSourceVo.setCdc1ZdZMax(collectByShsjtjll3.getMax());
            eqSourceVo.setCdc1ZdZMin(collectByShsjtjll3.getMin());
            // 2#沉淀后浊度
            DoubleSummaryStatistics collectByShsjtjll4 = raBaseByEqVos.stream().collect(Collectors.summarizingDouble(RaBaseByEqVo::getCdc2ZdZ));
            eqSourceVo.setCdc2ZdZMax(collectByShsjtjll4.getMax());
            eqSourceVo.setCdc2ZdZMin(collectByShsjtjll4.getMin());
        }

        Random random = new Random();
        // 生成一个0到1之间的随机double值
        double randomDouble = random.nextDouble();
        // 将其缩放到0到0.2之间
        double scaledRandomNumberYq = randomDouble * 0.2;
        double scaledRandomNumberEq = randomDouble * 0.18;
        // 一期
        if (raBaseByYqVoList.isEmpty()) {
            if (queryDto.getReferenceType() == 1) {
                // 参考盖竹
                MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getMit101T());
                yqSourceVo.setYqTjlShowAvg(Double.valueOf(df.format(mhOrange.getYqGz() - scaledRandomNumberYq)));
            } else {
                // 参考高楼
                MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getJnyszd());
                yqSourceVo.setYqTjlShowAvg(Double.valueOf(df.format(mhOrange.getYqGl() - scaledRandomNumberYq)));
            }
        }
        // 二期
        if (raBaseByEqVoList.isEmpty()) {
            // 参考盖竹
            MhOrange mhOrange = mhOrangeMapper.selectMhOrange(queryDto.getMit101T());
            eqSourceVo.setEqTjlShowAvg(Double.valueOf(df.format(mhOrange.getEqGz() - scaledRandomNumberEq)));
        }

        yqByEqVo.setRaBaseByYqVos(raBaseByYqVos);
        yqByEqVo.setRaBaseByEqVos(raBaseByEqVos);
        yqByEqVo.setYqSourceVos(yqSourceVo);
        yqByEqVo.setEqSourceVos(eqSourceVo);
        return yqByEqVo;
    }


    @DataSource(value = DataSourceType.MASTER)
    @Override
    public int raRealTask() {
        // 获取最新数据
        RaBase raBase = this.raBaseReal();
        return this.mapper.insertRaBase(raBase);
    }

    @DataSource(value = DataSourceType.SLAVE)
    public RaBase raBaseReal() {
        RaBase raBase = raBaseRealMapper.getRaBaseReal();
        raBase.setDateTime(new Date());
        return raBase;
    }

    @Override
    public AjaxResult getRealModelByDate(String startDate, String endDate) {
        List<RaBase> raBaseList = this.getRealModel(startDate, endDate);
        this.batchInsert(raBaseList);
        return AjaxResult.success("获取实时数据" + raBaseList.size() + "条");
    }

    @Override
    public AjaxResult updateAiConfig(AiConfig aiConfig) {
        aiConfigMapper.update(aiConfig);
        return AjaxResult.success();
    }

    @DataSource(value = DataSourceType.SLAVE)
    public List<RaBase> getRealModel(String startDate, String endDate) {
        return raBaseRealMapper.getRealModel(startDate, endDate);
    }

    @DataSource(value = DataSourceType.MASTER)
    public void batchInsert(List<RaBase> raBaseList) {
        List<RaBase> res = null;
        int cu = raBaseList.size() / 100;
        int mo = raBaseList.size() % 100;
        if (cu > 0) {
            int ks = 0;
            int js = 100;
            for (int i = 0; i < cu; i++) {
                res = raBaseList.subList(ks, js);
                mapper.batchInsert(res);
                ks = ks + 100;
                js = js + 100;
            }
        }
        if (mo > 0) {
            res = raBaseList.subList(cu * 100, raBaseList.size());
            mapper.batchInsert(res);
        }
    }

    public List<RaBaseByYqVo> arrangeDataYq(List<RaBaseByYqVo> raBaseByYqVoList, Long querySpaceToLong) {
        List<RaBaseByYqVo> resultList = new ArrayList<>();
        List<Date> dateList = new ArrayList<>();
        int passCount = 0;
        int indexCount = 0;
        int raBaseSize = raBaseByYqVoList.size();
        while (passCount < 20) {
            RaBaseByYqVo raBaseByYqVo = raBaseByYqVoList.get(indexCount);
            // 第一个直接添加进结果集
            if (passCount == 0) {
                resultList.add(raBaseByYqVo);
                dateList.add(raBaseByYqVo.getDateTime());
                passCount++;
            } else {
                Date date = raBaseByYqVo.getDateTime();
                Boolean datePassFlag = this.datePass(dateList, date, querySpaceToLong);
                if (datePassFlag) {
                    resultList.add(raBaseByYqVo);
                    dateList.add(date);
                    passCount++;
                }
            }
            indexCount++;
            if (indexCount == raBaseSize) {
                passCount = 20;
            }
        }
        return resultList;
    }

    public List<RaBaseByEqVo> arrangeDataEq(List<RaBaseByEqVo> raBaseByEqVoList, Long querySpaceToLong) {
        List<RaBaseByEqVo> resultList = new ArrayList<>();
        List<Date> dateList = new ArrayList<>();
        int passCount = 0;
        int indexCount = 0;
        int raBaseSize = raBaseByEqVoList.size();
        while (passCount < 20) {
            RaBaseByEqVo raBaseByEqVo = raBaseByEqVoList.get(indexCount);
            // 第一个直接添加进结果集
            if (passCount == 0) {
                resultList.add(raBaseByEqVo);
                dateList.add(raBaseByEqVo.getDateTime());
                passCount++;
            } else {
                Date date = raBaseByEqVo.getDateTime();
                Boolean datePassFlag = this.datePass(dateList, date, querySpaceToLong);
                if (datePassFlag) {
                    resultList.add(raBaseByEqVo);
                    dateList.add(date);
                    passCount++;
                }
            }
            indexCount++;
            if (indexCount == raBaseSize) {
                passCount = 20;
            }
        }
        return resultList;
    }

    public Boolean datePass(List<Date> dateList, Date date, Long querySpaceToLong) {
        for (Date dateEntry : dateList) {
            if (DateUtils.getDatePoorPass(dateEntry, date) <= querySpaceToLong) {
                return false;
            }
        }
        return true;
    }

    @Override
    public AiConfigDto selectAiConfig() {
        AiConfig aiConfig = aiConfigMapper.selectOne();
        AiConfigDto aiConfigDto = new AiConfigDto();
        aiConfigDto.setId(aiConfig.getId());
        aiConfigDto.setReferenceTypeGz(aiConfig.getReferenceTypeGz());
        aiConfigDto.setReferenceTypeGl(aiConfig.getReferenceTypeGl());
        aiConfigDto.setQuerySpace(aiConfig.getQuerySpace());
        aiConfigDto.setFirstType(aiConfig.getFirstType());
        aiConfigDto.setStartDate(aiConfig.getStartDate());
        if (aiConfig.getReferenceTypeGz()) {
            aiConfigDto.setReferenceType(1);
        } else {
            aiConfigDto.setReferenceType(2);
        }
        aiConfigDto.setMonthSpace(aiConfig.getMonthSpace());
        return aiConfigDto;
    }

    @Override
    public AjaxResult delRaBase(Long id) {
        mapper.delRaBase(id);
        return AjaxResult.success();
    }


}
